package com.gx.ring.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gx.ring.dao.RingBaseInterfaceDAO;
import com.gx.ring.entity.MonthFee;

public class MFInterfaceImplDAO implements RingBaseInterfaceDAO<MonthFee> {
	private Connection conn = null;

	public MFInterfaceImplDAO(Connection conn) {
		this.conn = conn;
	}

	@Override
	public List<MonthFee> queryByphNumber(String phNumber) throws SQLException {
		String sql = "SELECT * FROM ring.t_monthfee WHERE PHONENUMBER=? ";
		List<MonthFee> ls = new ArrayList<>();
		MonthFee mf = new MonthFee();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, phNumber);
		ResultSet rs = pst.executeQuery();
		while(rs.next()) {
			mf = saveResult(rs);
			ls.add(mf);
		}
		rs.close();
		pst.close();
		return ls;
	}



	@Override
	public MonthFee saveResult(ResultSet rs) throws SQLException {
		MonthFee mf = new MonthFee();
		mf.setMonthfeeid(rs.getLong("MONTHFEEID"));
		mf.setDataid(rs.getLong("DATAID"));
		mf.setServicetype(rs.getLong("SERVICETYPE"));
		mf.setPhonenumber(rs.getString("PHONENUMBER"));
		mf.setResourcecode(rs.getString("RESOURCECODE"));
		mf.setDatatype(rs.getInt("DATATYPE"));
		mf.setBillfee(rs.getInt("BILLFEE"));
		mf.setBegintime(rs.getTimestamp("BEGINTIME"));
		mf.setEndtime(rs.getTimestamp("ENDTIME"));
		mf.setWritetime(rs.getTimestamp("WRITETIME"));
		mf.setSendphonenumber(rs.getString("SENDPHONENUMBER"));
		mf.setOperateid(rs.getLong("OPERATEID"));
		mf.setMovetime(rs.getTimestamp("MOVETIME"));
		mf.setContent(rs.getString("CONTENT"));
		mf.setDatastatus(rs.getLong("DATASTATUS"));
		mf.setDataindex(rs.getLong("DATAINDEX"));
		mf.setLoopcount(rs.getInt("LOOPCOUNT"));
		mf.setLatestfailtime(rs.getTimestamp("LATESTFAILTIME"));
		mf.setLatestfailreason(rs.getString("LATESTFAILREASON"));
		mf.setLocalid(rs.getLong("LOCALID"));
		mf.setBrandid(rs.getLong("BRANDID"));
		mf.setNetkind(rs.getLong("NETKIND"));
		mf.setPaykind(rs.getLong("PAYKIND"));
		mf.setChargeflag(rs.getLong("CHARGEFLAG"));
		mf.setUsdpip(rs.getString("USDPIP"));
		return mf;
	}

}
